*WHAT'S ACROSS THE BORDER?
*JHA, NEUMARK, AND RODRIGUEZ-LOPEZ

include directories.do


*********************************************county full sample*********************************


foreach geo in "co" "cz" {


drop _all

set more off
 
use "`dlrdir'`s'QCEWindustry_minwage_contig_`geo'.dta"

*TO CORRECT DRL'S STANDARD ERRORS IN COUNTY-PAIR REGRESSIONS (PAIRTIMES==2)
merge m:1 pair_id using "`dlrdir'`s'`geo'_pairs_dlr.dta"

drop if _merge==2
drop _merge

************   residual leads/lags ***********

tsset pair_id_county period
 
forval j = 2(2)16 {
 
	gen lnMW_l`j' =  L`j'.lnMW 
       
      gen lnMW_f`j' = F`j'.lnMW 
     
} 


 
gen lnMW_l0 = lnMW

gen sampleperiod = (year>=1990 & (year<2006) | (year ==2006 & quarter<3) )

keep if nonmissing_rest_both==66

forval j = 2(2)16 {
 
      xi: qui areg lnMW_l`j' if sampleperiod  ,  absorb(countyreal)
      predict lnMWR_l`j', res
      xi: qui areg lnMW_f`j' if sampleperiod  ,  absorb(countyreal)
      predict lnMWR_f`j', res       
    
} 

*****************************

local varlist1 "lnemp_rest_both lnemp_TOT lnpop lnMW lnAWW_rest_both lnAWW_TOT  "

foreach var of local varlist1 {

cap drop `var'R
   
xi: qui areg `var' if sampleperiod , absorb(countyreal)
predict `var'R, res

}

 

********   specifications 1 and 2  ****
* spec 3 =  contiguous county 	  *
*  						  *
***************************************

  
egen pair_id_num = group(pair_id)

gen sample_3 = 1
egen absorb_3 = group(pair_id period)
egen stperiod = group(state_fips period)

sort  pair_id period
 
gen state_a = real(substr(pair_id, 1,2))
gen state_b = real(substr(pair_id, 7,2))

gen st_min = min( state_a, state_b)
gen st_max = max(state_a, state_b)

egen bordersegment = group(st_min st_max)
egen bordersegmentperiod = group(bordersegment period)

 

tsset pair_id_county period

gen lnMWR_f12_f4=lnMWR_f12-lnMWR_f4
gen lnMWR_f4_f0=lnMWR_f4-lnMWR

local MWleads "lnMWR_f12 lnMWR_f4 lnMWR"
local MWleads2 "lnMWR_f12_f4 lnMWR_f4_f0 lnMWR"
local varlist2 "lnemp_rest_both lnemp_TOT"
local varlist3 "lnemp_rest_both   lnemp_TOT lnAWW_rest_both   lnAWW_TOT" 

  
set more off

eststo m1_rest_`geo':  xi: cluster2areg lnemp_rest_bothR  `MWleads2' lnemp_TOTR lnpopR  if pairtimes==2 ,  tcluster(state_fips) fcluster(bordersegment)  a(absorb_3) w(all)
	
eststo m2_rest_`geo':	xi: cluster2areg lnemp_rest_bothR  `MWleads' lnemp_TOTR lnpopR  if pairtimes==2 ,  tcluster(state_fips) fcluster(bordersegment)  a(absorb_3) w(all)

eststo m3_tot_`geo':  xi: cluster2areg lnemp_TOTR  `MWleads2' lnpopR  if pairtimes==2 ,  tcluster(state_fips) fcluster(bordersegment)  a(absorb_3) w(all)
	
eststo m4_tot_`geo':	xi: cluster2areg lnemp_TOTR  `MWleads' lnpopR  if pairtimes==2 ,  tcluster(state_fips) fcluster(bordersegment)  a(absorb_3) w(all)

}

/* Print results */

tempfile specs

#delimit ;
esttab m1_rest_co m2_rest_co m3_tot_co m4_tot_co m1_rest_cz m2_rest_cz m3_tot_cz m4_tot_cz using "`specs'.csv",
	nodepvars
	collabels(, none)
	mlabels(, none)
	b(%9.3f) se(%9.3f)
	star(* .10 ** .05 *** .01)
	title("DLR specification (6) -- PRE-TRENDS")
	order(`MWleads2' `MWleads' lnpopR)
	nonotes
	label
	stats(N, labels("N") fmt(0 0))	
	replace;
#delimit cr

* Switch the output to Excel format
insheet using "`specs'.csv", comma clear
export excel "`outdir'`s'TablesJNR.xlsx", sheetreplace sheet(Table7_DLR)
clear all


